package com.sandu.network.repository;

import android.util.Log;


import com.sandu.network.service.ApiClient;
import com.sandu.network.utils.JsonUtil;
import com.sandu.network.utils.SwitchSchedulers;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
import okhttp3.ResponseBody;

/**
 * Created by clark on 2024/11/15.
 * 动态url数据获取
 */

public class DynamicDataRepository {

    public static <T> Observable getDynamicData(String pullUrl, final Class<T> clazz) {

        return
                ApiClient
                        .getDynamicDataService()
                        .getDynamicData(pullUrl)
                        .compose(SwitchSchedulers.applySchedulers())
                        .map(new Function<ResponseBody, T>() {
                            @Override
                            public T apply(ResponseBody responseBody) throws Exception {
                                Log.d("clark", JsonUtil.JsonBean2Str(responseBody));
                                return JsonUtil.Str2JsonBean(responseBody.string(), clazz);
                            }
                        });
    }


}